package com.swlz.service.impl;

import java.sql.SQLException;

import com.swlz.dao.FictionSectionDAO;
import com.swlz.entity.FictionSection;
import com.swlz.exception.CodeException;
import com.swlz.service.FictionSectionService;
import com.swlz.vo.PageVO;

/**
 * <pre>
 * 业务逻辑接口具体实现类
 * 小说章节
 * ClassName : com.swlz.service.impl.FictionSectionServiceImpl
 * Author : swlz
 * E-Mail : 2233875735@qq.com
 * Date : 2020-06-30 12:12:07
 * Version : 1.0
 * Copyright 2020 swlz.top Inc. All rights reserved. 
 * Warning: this content is only for internal circulation of the company. It is forbidden to divulge it or use it for other commercial purposes
 * </pre>
 **/
public class FictionSectionServiceImpl implements FictionSectionService {
	
	private FictionSectionDAO fictionSectionDAO = new FictionSectionDAO();

	@Override
	public int add(FictionSection fictionSection) throws CodeException {
		try {
			return fictionSectionDAO.insertSelective(fictionSection);
		} catch (SQLException e) {
			throw new CodeException(500, "添加小说章节错误",e);
		}
	}

	@Override
	public int update(FictionSection fictionSection) throws CodeException {
		try {
			return fictionSectionDAO.updateSelective(fictionSection);
		} catch (SQLException e) {
			throw new CodeException(501, "修改小说章节错误",e);
		}
	}

	@Override
	public int delete(Long sectionId) throws CodeException {
		try {
			return fictionSectionDAO.deleteById(sectionId);
		} catch (SQLException e) {
			throw new CodeException(502, "删除小说章节错误",e);
		}
	}

	@Override
	public FictionSection get(Long sectionId) throws CodeException {
		try {
			return fictionSectionDAO.selectById(sectionId);
		} catch (SQLException e) {
			throw new CodeException(503, "获取小说章节失败",e);
		}
	}

	@Override
	public PageVO<FictionSection> page(FictionSection fictionSection, Integer current, Integer rowMax) throws CodeException {
		try {
			long total = fictionSectionDAO.countByModel(fictionSection);
			PageVO<FictionSection> page = new PageVO<>(total, current, rowMax);
			return page.setList(fictionSectionDAO.selectByModel(fictionSection, page.getOffset(), page.getRowMax()));
		} catch (SQLException e) {
			throw new CodeException(504, "获取小说章节分页数据失败",e);
		}
	}


}
